package com.nisco.nio.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * file channel 通道间数据传输
 **/
public class FileChannelTransfer {
    public static void main(String[] args)
        throws IOException {
        RandomAccessFile rfa = new RandomAccessFile("E:/aa.txt", "rw");
        RandomAccessFile rfb = new RandomAccessFile("E:/bb.txt", "rw");
        FileChannel channelA = rfa.getChannel();
        FileChannel channelB = rfb.getChannel();

        long len = channelB.transferTo(0, channelB.size(), channelA);
        System.out.println(len);

        channelA.close();
        channelB.close();
        rfa.close();
        rfb.close();
    }
}
